import { LAYER_CHANGE_TYPE } from "../common/GameConfig";
import LayerStatic from "../common/LayerStatic";
import PanelBase from "../common/PanelBase";
import EventManager from "../core/event/EventManager";
import { Event_Name } from "../core/event/event_mgr";
import RankItem from "./RankItem";
import { Http1 } from "./http/Http1";


const { ccclass, property } = cc._decorator;

@ccclass
export default class Rank extends PanelBase {

    // @property
    // text: string = 'hello';

    @property(cc.Node) content: cc.Node = null;
    @property(cc.Prefab) pre: cc.Prefab = null;


    onLoad() {
        LayerStatic.Instance.setRankStatic(this);
    }

    protected onEnable(): void {
        super.onEnable();
    }

    start() {
        Http1.get("/index/granking", {}, (data) => {
            this.setAll(data);
        }, this)
    }

    protected onDestroy(): void {
        LayerStatic.Instance.setRankStatic(null);
    }


    setAll(data) {
        data.ranking.forEach((value, index) => {
            let node = cc.instantiate(this.pre);
            this.content.addChild(node);
            let item = node.getComponent(RankItem);
            item.setAll(value, index)
        });

    }




    private onRechange() {
        this.onClose();
    }




    // update (dt) {}
}
